import { Loading } from 'element-ui';

let loadingInstance;

export default {
  install (Vue) {
    // 将所有 modal 相关方法封装到 $modal 下
    Vue.prototype.$modal = {
      // 打开遮罩层
      loading (content) {
        loadingInstance = Loading.service({
          lock: true,
          text: content,
          spinner: "el-icon-loading",
          background: "rgba(0, 0, 0, 0.7)",
        });
      },

      // 关闭遮罩层
      closeLoading () {
        if (loadingInstance) {
          loadingInstance.close();
        }
      },

      // 其他 modal 相关方法，例如 msg、alert、notify 等
      msg (content) {
        this.$message.info(content);
      },
      msgError (content) {
        this.$message.error(content);
      },
      msgSuccess (content) {
        this.$message.success(content);
      },
      alert (content) {
        this.$messageBox.alert(content, "系统提示");
      },
      confirm (content) {
        return this.$messageBox.confirm(content, "系统提示", {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: "warning",
        });
      },
    };
  },
};
